package utils

import (
	"mars-backend/constants"

	"github.com/astaxie/beego"

	mgo "gopkg.in/mgo.v2"
)

//GetMongoSession 获取Mongo连接
func GetMongoSession() (*mgo.Session, error) {
	url := beego.AppConfig.String(constants.MongoDBURL)
	session, err := mgo.Dial(url)
	if err != nil {
		return nil, err
	}

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	return session, err
}
